package ${packageName};


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.support.ex.BuzEx;
import org.support.mybatis.page.Page;
import org.support.mybatis.page.PageHelper;
import org.support.response.AjaxJson;
import com.adinnet.aiyike.response.code.CCode;

import ${MODEL_URL};
import ${SERVICE_URL};

/**
 * ${description}
 * @author ${annotation.authorName}
 * @date ${annotation.date}
 * @version ${annotation.version}
 */
@Controller
@RequestMapping("api/${classNameLower}")
public class ${className}${classSuffix} {
     private static LogModule log = BuzLog.log();
    
    @Autowired
	private ${servicePrefix}${className}${serviceSuffix} ${classNameLower}${serviceSuffix};
	
	
	
	@RequestMapping(value="list")
	@ResponseBody
	public AjaxJson list(${className} ${classNameLower},PageHelper helper){
		try {
			Page<${className}>page=${classNameLower}${serviceSuffix}.query${className}ByPage(helper,${classNameLower});
			return AjaxJson.OK(page);
		} catch (BuzEx e) {
            return AjaxJson.Fail(e);
        } catch (Exception e) {
            return AjaxJson.Fail(CCode.C_Query_FAILD);
        }
	}
	
 	@RequestMapping(value="add")
	@ResponseBody
	public AjaxJson add(${className} ${classNameLower}){
		try {
			Integer id=${classNameLower}${serviceSuffix}.save(${classNameLower});
			return AjaxJson.OK(id);
		} catch (BuzEx e) {
            return AjaxJson.Fail(e);
        } catch (Exception e) {
            return AjaxJson.Fail(CCode.C_SAVE_FAILED);
        }
	}
	
	<#list colList as col>
 		<#if col.isPK==1>
 	@RequestMapping(value="del/{id}")
	@ResponseBody
	public AjaxJson del(@PathVariable ${col.simpleFieldType} id){
		try {
			int result=${classNameLower}${serviceSuffix}.deleteByPrimaryKey(id);
			return AjaxJson.OK();
		} catch (BuzEx e) {
            return AjaxJson.Fail(e);
        } catch (Exception e) {
            return AjaxJson.Fail(CCode.C_DELETE_FAILED);
        }
	}
 		</#if>
 	</#list>
	
	
	@RequestMapping(value = "update")
	@ResponseBody
	public AjaxJson update(${className} ${classNameLower}) {
		try {
			int result=${classNameLower}${serviceSuffix}.updateByPrimaryKey(${classNameLower});
			return AjaxJson.OK();
        } catch (BuzEx e) {
            return AjaxJson.Fail(e);
        } catch (Exception e) {
            return AjaxJson.Fail(CCode.C_UPDATE_FAILED);
        }
	}
	
	
	<#list colList as col>
 	<#if col.isPK==1>
	@RequestMapping(value="detail/{id}")
	@ResponseBody
	public AjaxJson detail(@PathVariable ${col.simpleFieldType} id){
		try {
			${className} ${classNameLower}=${classNameLower}${serviceSuffix}.selectByPrimaryKey(id);
			AjaxJson j = new AjaxJson();
            j.setResult(${classNameLower});
            return j;
        } catch (BuzEx e) {
            return AjaxJson.Fail(e);
        } catch (Exception e) {
            return AjaxJson.Fail(CCode.C_Query_FAILD);
        }
	}
	</#if>
 	</#list>
}
